import TableLyout from "@/components/commonPublic/tableLyout.vue";
import publicForm from "@/components/materialDataManage/fromCom.vue"; //模糊查询
import TableData from "@/components/public/el-table"; //主页面列表
import formJs from "./regexDetail.js"; //新增弹框配置项
import actions from "@/actions";
import API from '@/utils/commonRequest.js';


import {
    getMangEquipmentPageList, //主页面列表接口

} from "@/api/request.js";
// import { statusType2 } from "@/utils/config"; //配置项
export default {
    name: "rebarDetectionEquipment",
    components: {
        TableLyout,
        publicForm,
        TableData,
    },
    data() {
        return {
            name: "rebarDetectionEquipment", //按钮配置页面代号
            searchObj: formJs.searchObj, //搜索条件
            queryCriteriaData: {}, //分页
            userNature: null, //用户Nature
            tendersObj: [],//标段list
            projectsObj: [], //项目名

           
            // 列表
            isLock: false,
            currentRow: null, //列表详情
            btnObj: formJs.btnObj, //按钮
            table_config: formJs.table_config,
            tableData: [], //列表数据列表
            loading: false, //列表数据加载loading
            getList: {
                modelType: "2", // 0代办 1已办
                fprojectid: "",
                fCompanyid: "", //机构id
                fUserid: "", //当前登录用户id
                sublevel: 1, //查看下级  1是0否
                keyWord: "", //设备名称模糊查询字段
                keyType: "", //设备类型
                page: 1, // 当前页码
                pageSize: 15, // 每页显示条数
                fNote: "2",//1回弹  2钢保
                startDates: "", // 开始时间
                endDates: "", // 截至时间
                timeDates: [],
            }, // 列表给后端传参
            // 列表
            userInfo: {}, //登录用户
        };
    },

    mounted() {
        API.userNature().then((res) => {
            if (res.errcode == 0) {
                this.userNature = res.data.Nature;
            }
        }).catch((err) => {
            console.log("API", err)
        })
        actions.onGlobalStateChange((state, prev) => {
            var data = prev.currentUser.projects;
            this.projectsObj = data;
            this.userInfo = prev.currentUser
        }, true);
        this.getDate();
    },
    methods: {
        // 重置
        reset(e) {
            this.getList = this.$options.data.call(this).getList;
            this.getList.fprojectid = e;
        },
        getBtnName(name, status) {
            this.yj_edit(status);
        },
        // 新增/编辑
        yj_edit(num) {
            var data;
            if (num == 7) { //查看
                if (this.currentRow != null) {
                    this.$router.push({
                        path: "/rebarThicknessManage/rebarDataDictionary/rebarDetectionEquipmentText",
                    });
                    data = {
                        data: this.currentRow,
                        getList: this.getList,
                        status: num,
                    }
                } else {
                    this.$message.error({
                        content: "请先选择需要查看的数据",
                        duration: 1000
                    });

                }
            }
            sessionStorage.setItem("GxEmbedded-rebarThicknessManage_rebarDetectionEquipment", JSON.stringify(data));
        },
        // 获取列表数据
        yj_searchForm(data) {
            window.sessionStorage.setItem(
                "GxEmbedded-rebarThicknessManage_getList",
                JSON.stringify(data)
            );
            var id;
            if (data.fCompanyid != "") {
                id = data.fCompanyid;
            } else {
                id = data.fprojectid;
            }
            var obj = {
                modelType: "2", // 0代办 1已办
                fCompanyid: id, //机构id
                fUserid: this.userInfo.id, //当前登录用户id
                sublevel: 1, //查看下级  1是0否
                keyWord: data.keyWord, //设备名称模糊查询字段
                keyType: "", //设备类型
                page: data.page, //当前页码
                pageSize: data.pageSize, //每页显示条数
                fNote: "2",//1回弹  2钢保

            };
            // var obj = {
            //     fCompanyid: "16efa5f0-ef31-4ca5-be1f-846492bb3097",
            //     fNote: "2",
            //     fUserid: "System",
            //     keyType: "",
            //     keyWord: "",
            //     modelType: "2",
            //     page: 1,
            //     pageSize: 20,
            //     sublevel: 1,
            // }
            this.loading = true;
            var that = this;
            getMangEquipmentPageList(obj)
                .then((res) => {
                    if (res.errcode == 0) {
                        that.loading = false;
                        that.tableData = res.data.mangEquipmentList.list;
                        this.queryCriteriaData = res.data.mangEquipmentList;
                    } else {
                        this.$message.error("列表数据获取失败", res.msg);
                        this.loading = false;
                    }
                })
                .catch((error) => {
                    console.log("列表数据 接口出错" + error.msg);
                    this.loading = false;
                });
        },

        // 查看
        yj_viewForm(row, label) {
            this.currentRow = row;
            if (label == "设备编码") {
                this.yj_edit(7);
            }
        },

        // 点击当前行
        rowChange(val) {
            this.currentRow = val;
            return val;
        },

        //获取时间
        getDate() {
            if (JSON.parse(sessionStorage.getItem("GxEmbedded-rebarThicknessManage_getList"))) {

                var dataList = JSON.parse(
                    sessionStorage.getItem("GxEmbedded-rebarThicknessManage_getList")
                );
                if (dataList.fprojectid != "") {
                    this.getTender(dataList.fprojectid);
                } else {
                    data.fprojectid = this.projectsObj[1].fItemValue;
                    this.getTender(dataList.fprojectid);
                }
                if (dataList.startDates == "" || dataList.startDates == undefined || dataList.startDates == null || dataList.endDates == "" || dataList.endDates == undefined || dataList.endDates == null) {
                    dataList.startDates = this.common.getDay(-90); // 开始时间
                    dataList.endDates = this.common.getDay(0); // 截至时间
                }
                this.getList = {
                    modelType: "2", // 0代办 1已办
                    fprojectid: dataList.fprojectid,
                    fCompanyid: dataList.fCompanyid, // 左侧选中组织机构id
                    fUserid: this.userInfo.id,//当前登录用户id
                    sublevel: 1, //查看下级  1是0否
                    keyWord: "", //设备名称模糊查询字段
                    keyType: "", //设备类型
                    page: 1, // 当前页码
                    pageSize: 15, // 每页显示条数
                    fNote: "2",//1回弹  2钢保
                    startDates: dataList.startDates, // 开始时间
                    endDates: dataList.endDates, // 截至时间
                    timeDates: [dataList.startDates, dataList.endDates],
                };
            } else {
                this.getList.startDates = this.common.getDay(-90); // 开始时间
                this.getList.endDates = this.common.getDay(0); // 截至时间
                this.getList.timeDates = [
                    this.getList.startDates,
                    this.getList.endDates,
                ];

            }
        },

       


        // 筛选条件
        async getTender(e) {
            await this.$http(
                " http://172.18.5.31:8300/IOTManagement/Base/Company/getGXJLBaseCompanyList.do?projectId=" +
                e, {
                headers: {
                    "Content-Type": "application/json",
                    Authorization: localStorage.getItem("access_token"),
                },
            }
            ).then((res) => {
                if (res.status == 200) {
                    var data = res.data.data.GXCompanyList;
                    this.tendersObj = [];
                    if (data.length == 0) {
                        this.$message.warning({
                            content: "有其他人员登录此账号！",
                            duration: 1000,
                        });
                        setTimeout(() => {
                            window.location.href = "http://172.18.5.201:1080/login";
                        }, 1200);
                    } else   if (data.length == 1) {
                        data.map((item) => {
                            this.tendersObj.push({
                                fItemName: item.sectionName,
                                fItemValue: item.sectionId,
                            });
                        });
                        this.getList.fCompanyid = data[0].sectionId;
                    } else {
                        this.tendersObj = [{
                            fItemName: "所有标段",
                            fItemValue: "",
                        },];
                        data.map((item) => {
                            this.tendersObj.push({
                                fItemName: item.sectionName,
                                fItemValue: item.sectionId,
                            });
                        });
                    }
                }
            });
        },

        selectCompanyid(e, index, prop) {
            console.log("selectCompanyid", e, index, prop);
        },

        // 筛选条件
    },
};